<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_Upload_module extends CI_Module
{
	/**
	 * 
     * 构造函数
     */
    public function __construct(){
        parent::__construct();

        $this->load->model('admin.Upload_model');
    }
	/**
	 * 
	 * 上传图片文件处理
	 */
	function ajax_upload(){
        //上传配置文件
        $config = $this->Upload_model->upload_config();
        $this->load->library('upload',$config);
        $absolute_path = str_replace('\\', '/', getcwd()).'/';
        if ( ! $this->upload->do_upload('file'))
        {
            $error = array('error' => $this->upload->display_errors());
            $this->error($error['error'],'',true);
        }else
        {
            $data = array('upload_data' => $this->upload->data());
            $message = str_replace($absolute_path, '', $data['upload_data']['full_path']);

            $this->success($message,'',true);
        }
	}

    /**
     * 上传视频文件
     */
    function ajax_file_upload(){
        //上传配置文件
        $config = $this->Upload_model->upload_config();
        $this->load->library('upload',$config);
        $absolute_path = str_replace('\\', '/', getcwd()).'/';
        if ( ! $this->upload->do_upload('file'))
        {
            $error = array('error' => $this->upload->display_errors());
            $this->error($error['error'],'',true);
        }else
        {
            $data = array('upload_data' => $this->upload->data());
            $message = str_replace($absolute_path, '', $data['upload_data']['full_path']);
            
            $this->Upload_model->ftp_upload($message);
            $this->success($message,'',true);
        }
    }

    //缩略图生成
    public function pic(){
        $file= 'uploads/20140812/4dad45a47f83f094c98ce85efebaf793.jpg';
        $file = $this->thumbnail_process($file,'100','100');
        echo $file;exit;
    }


}